package de.tum.in.eist.poll.shared.beans;

import java.io.Serializable;


/**
 * A Lecture represents a lecture given by a lecturer at
 * a specific point in time, so a Lecture does not represent
 * a series of lectures. Each lecture also consists of
 * a bunch of questions to ask the students.
 * 
 * @author The EIST-POLL-21 team.
 *
 */
public class Lecture implements Serializable {
	/**
	 * serialization version
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * The questions the poll for this lecture should ask for
	 */
	private QuestionGroup questions;
	
	/**
	 * The ID of the lecturer this lecture belongs to
	 */
	private String lecturerID;
	
	/**
	 * This lecture's title
	 */
	private String title;
	
	/**
	 * Unique ID of this lecture
	 */
	private String lectureID;
	
	/**
	 * indicates whether a poll is closed
	 */
	private boolean pollClosed = false;
	
	
	/**
	 * Dummy constructor for GWT. Don't use.
	 */
	public Lecture() {
		this("DummyLecture", new Lecturer().getUserID(), "Dummy Lecture",
				new QuestionGroup());
	}

	public Lecture(String lectureID, String lecturerID, String title, QuestionGroup questions) {
		this.lectureID = lectureID;
		this.lecturerID  = lecturerID;
		this.title     = title; 
		this.questions = questions;
	}

	/**
	 * @return lecture ID
	 */
	public String getLectureID() {
		return lectureID;
	}
	
	/**
	 * @return lecture title
	 */
	public String getLectureTitle() {
		return title;
	}
	
	/**
	 * @return The ID of the lecturer of this lecture
	 */
	public String getLecturerID() {
		return lecturerID;
	}

	/**
	 * @return questions associated with this lecture. 
	 */
	public QuestionGroup getQuestions() {
		return questions;
	}
	
	/**
	 * close the poll for this lecture
	 */
	public void closePoll() {
		pollClosed = true;
	}
	
	/**
	 * indicates whether the poll is closed already or not
	 * @return
	 */
	public boolean isPollClosed() {
		return pollClosed;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((lectureID == null) ? 0 : lectureID.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Lecture other = (Lecture) obj;
		if (lectureID == null) {
			if (other.lectureID != null)
				return false;
		} else if (!lectureID.equals(other.lectureID))
			return false;
		return true;
	}
}
